function validate(name, password) {
  let errors = {};
  if (!name || !(/^[a-zA-Z][a-zA-Z0-9]*/.test(name))) {
    errors = errors || {};
    errors.name = "请输入以字母开头的英文和数字";
  }

  if (!(/^[a-zA-Z0-9]{3,12}$/.test(password))) {
    errors = errors || {};
    errors.password = "密码要求3 ~ 12位的英文和数字";
  }
  return errors;
}

function register_validate(name, password, confirm_password) {
  let errors = {};
  if (!name || !(/^[a-zA-Z][a-zA-Z0-9]*/.test(name))) {
    errors = errors || {};
    errors.name = "请输入以字母开头的英文和数字";
  }

  if (!(/^[a-zA-Z0-9]{3,12}$/.test(password))) {
    errors = errors || {};
    errors.password = "密码要求3 ~ 12位的英文和数字";
  }
  if (password !== confirm_password) {
    errors = errors || {};
    errors.confirm_password = "两次密码不一致";
  }
  return errors;
}

if (typeof window === "undefined") {
  exports.validate = validate;
  exports.register_validate = register_validate;
}
